<script>
function valid()
{
 alert("hi");
  if(document.f1.name.value=="")
  {
   alert("Enter Name");
   document.f1.name.focus();
   return false;
  }
  if(document.f1.emailid.value=="")
  {
   alert("Enter EmailId");
   document.f1.emailid.focus();
   return false;
  }
  if(document.getElementById('emailid').value!='')
		{			
   			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   			var address = document.getElementById('emailid').value;
   			if(reg.test(address) == false) 
			{
      			alert('Invalid Email Address');
				document.getElementById('emailid').focus();
      			return false;
   			}
		}  
  if(document.f1.password.value=="")
  {
   alert("Enter password");
   document.f1.password.focus();
   return false;
  }
  if(document.f1.fname.value=="")
  {
   alert("Enter password");
   document.f1.fname.focus();
   return false;
  }
  if(document.f1.lname.value=="")
  {
   alert("Enter password");
   document.f1.lname.focus();
   return false;
  }
  if(document.f1.address1.value=="")
  {
   alert("Enter Address1");
   document.f1.address1.focus();
   return false;
  }
  if(document.f1.address2.value=="")
  {
   alert("Enter Address1");
   document.f1.address2.focus();
   return false;
  }
  if(document.f1.lname.value=="")
  {
   alert("Enter password");
   document.f1.lname.focus();
   return false;
  }
  
}
</script>
<form name="f1" method="post">
<table>
<tr><td>Name:</td><td><input type="text" name="name" id="name"/></td></tr>
<tr><td>Email:</td><td><input type="text" name="emailid" id="emailid"/></td></tr>
<tr><td>Password:</td><td><input type="text" name="password" id="password"/></td></tr>
<tr><td>First Name:</td><td><input type="text" name="fname" id="fname"/></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="lname" id="lname"/></td></tr>
<tr><td>Address1:</td><td><textarea name="address1" id="address1"></textarea></td></tr>
<tr><td>Address2:</td><td><textarea name="address2" id="address2"></textarea></td></tr>
<tr><td>Country:
</td><td><select name="Country" id="Country" ><option>Select Country</option>
<?php
 foreach($countryval as $cn){
  
			$id=$cn['id'];
			$value=$cn['value'];
			?>
			
			<option value='<?php echo $id; ?>'><?php echo $value; ?></option>
			
			<?php } ?>
</select></td></tr>
<tr><td>State:</td><td><select name="State" id="State"><option value="0">Select State</option></select></td></tr>
<tr><td>City:</td><td><select name="City" id="City"><option value="0">Select City</option></select></td></tr>
<tr><td><input value="Submit"  type="submit" onclick="return valid();"/></td></tr>

</table>
</form>